<template name="交易信息配置">
  <div class="page">
    <a-form-model
      layout="inline"
      class="form section"
      :form="query"
      @submit="search"
    >
      <a-form-model-item label="内部交易码">
        <a-input
          placeholder="请输入内部交易码"
          class="select"
          v-model="query.txnNum"
        />
      </a-form-model-item>
      <a-form-model-item label="业务产品代码">
        <a-input
          placeholder="请输入业务产品代码"
          class="select"
          v-model="query.bizProdCode"
        />
      </a-form-model-item>
      <a-form-model-item>
        <a-button type="primary" html-type="submit">搜索</a-button>
      </a-form-model-item>
    </a-form-model>
    <div class="section">
      <div class="btn-group">
        <a-button type="primary" @click="openModal()">
          <a-icon type="plus" />
          <span>增加</span>
        </a-button>
      </div>
      <a-table
        ref="table"
        :columns="columns"
        :dataSource="dataSource"
        :rowKey="(record,index)=>{return index}"
        :loading="loading"
        :pagination="pagination"
        @change="onChange"
        @showSizeChange="onChange"
        :scroll="{ x: 3600 }"
      >
        <template slot="operation" slot-scope="text, record">
          <a-icon type="setting" theme="twoTone" twoToneColor="#4a9ff5" @click="edit(record)" title="修改" ></a-icon>


          <a-popconfirm
            title="确定要启用吗？"
            @confirm="cancel(record)"
            v-if="record.supportFlag !== 'Y'"
          >
            <a-icon type="check-circle" theme="twoTone" twoToneColor="#4a9ff5" title="启用"></a-icon>
          </a-popconfirm>
          <a-popconfirm
            title="确定要停用吗？"
            @confirm="cancel(record)"
            v-if="record.supportFlag !== 'N'"
          >
            <a-icon type="minus-circle" theme="twoTone" twoToneColor="#4a9ff5" title="停用"></a-icon>
          </a-popconfirm>
          <!--          <a-->
          <!--            class="text-btn"-->
          <!--            @click="edit(record)"-->
          <!--            >修改</a-->
          <!--          >-->
          <!--          <a-popconfirm-->
          <!--            title="确定要启用吗？"-->
          <!--            @confirm="cancel(record)"-->
          <!--            v-if="record.supportFlag !== 'Y'"-->
          <!--          >-->
          <!--            <a class="text-btn danger">启用</a>-->
          <!--          </a-popconfirm>-->
          <!--          <a-popconfirm-->
          <!--            title="确定要停用吗？"-->
          <!--            @confirm="cancel(record)"-->
          <!--            v-if="record.supportFlag !== 'N'"-->
          <!--          >-->
          <!--            <a class="text-btn danger">停用</a>-->
          <!--          </a-popconfirm>-->
          <!--          <a-->
          <!--            class="text-btn"-->
          <!--            @click="view(record)"-->
          <!--            >查看</a-->
          <!--          >-->
          <a-icon type="eye" theme="twoTone" twoToneColor="#4a9ff5" @click="view(record)" title="详情" ></a-icon>
        </template>
      </a-table>
    </div>
    <a-modal
      v-model="modalVisible"
      :title="modalTitle"
      width="800px"
      @ok="submit"
      :maskClosable="false"
    >
      <p-txn-cfg-operation ref="modalForm" :query="query" />
    </a-modal>
  </div>
</template>

<script>
  import PTxnCfgOperation from "./PTxnCfgOperation";

  export default {
    name: "PTxnCfg",
    components: { PTxnCfgOperation },
    data() {
      return {
        query: {
          txnNum: "",
          bizProdCode: "",
        },
        beanInfo: {},
        modalVisible: false,
        modalTitle: "",
        operationType: "view",
        loading: false,
        pagination: {
          pageNum: 1,
          pageSize: 10,
          pageSizeOptions: ["10", "20", "30", "40", "100"],
          defaultCurrent: 1,
          defaultPageSize: 10,
          showQuickJumper: true,
          showSizeChanger: true,
          showTotal: (total, range) =>
            `显示 ${range[0]} ~ ${range[1]} 条记录，共 ${total} 条记录`,
        },
        columns: [
          {
            title: "内部交易码",
            dataIndex: "txnNum",
            fixed: "left",
            width: 120,
          },
          {
            title: "交易描述",
            dataIndex: "txnName",
            width: 120,
          },
          {
            title: "业务细分",
            dataIndex: "bizType",
            width: 120,
          },
          {
            title: "交易分组",
            dataIndex: "txnGroup",
            width: 120,
          },
          {
            title: "业务产品代码",
            dataIndex: "bizProdCode",
            width: 200,
            customRender: (text, row, index) => {
              switch (text) {
                case '00':
                  return  "基础公共"
                case '01':
                  return  "刷卡支付"
                case '02':
                  return "付款扫码(主扫)"
                case '03':
                  return "收款扫码(被扫) "
                case '04':
                  return "信用卡分期"
                case '05':
                  return "银行卡支付"
                case '06':
                  return "XX手机银行支付"
                default:
                  return text
              }
            },
          },
          {
            title: "交易超时时间",
            dataIndex: "txnTimeout",
            width: 120,
          },
          {
            title: "超时交易处理码",
            dataIndex: "excpTxnNum",
            width: 200,
          },
          {
            title: "超时服务处理方式",
            dataIndex: "excpHandleFlag",
            width: 200,
            customRender: (text) => {
              return text ? ["同步处理", "异步处理"][text] : "";
            },
          },
          {
            title: "超时处理服务类名",
            dataIndex: "excpServiceName",
            width: 200,
          },
          {
            title: "存储转发间隔类型",
            dataIndex: "safGapType",
            width: 200,
            customRender: (text) => {
              return text ? ["等时长间隔", "等幂间隔"][text] : "";
            },
          },
          {
            title: "超时重试次数",
            dataIndex: "repeatNum",
            width: 120,
          },
          {
            title: "超时重试时间间隔",
            dataIndex: "repeatTime",
            width: 120,
          },
          {
            title: "交易支持标志",
            dataIndex: "supportFlag",
            width: 120,
            customRender: (text,row,index) => {
              switch (text) {
                case 'Y':
                  return  "支持"
                case "N":
                  return "不支持"
                default :
                  return text
                }
            },
          },
          {
            title: "交易支持开始时间",
            dataIndex: "supportBeginTime",
            width: 200,
          },
          {
            title: "交易支持截止时间",
            dataIndex: "supportEndTime",
            width: 200,
          },
          {
            title: "流水表登记标识",
            dataIndex: "txnRegisterFlag",
            width: 200,
            customRender: (text,row,index) => {
              switch (text) {
                case 'P':
                  return  "登记金融流水"
                case 'T':
                  return  "登记非金融流水表"
                case 'M':
                  return "登记管理流水表"
                case 'N':
                  return "不登记流水"
                default:
                  return text
              }
            },
          },
          {
            title: "业务报文登记标识",
            dataIndex: "msgRegisterFlag",
            width: 200,
            customRender: (text,row,index) => {
              switch (text) {
                case 'Y':
                  return "登记"
                case 'N':
                  return "不登记"
              }
            },
          },
          {
            title: "验签标志",
            dataIndex: "signFlag",
            width: 200,
            customRender: (text) => {
              return text
                ? {
                  Y: "验签/MAC",
                  N: "不验签/MAC",
                }[text]
                : "";
            },
          },
          {
            title: "转加密标志",
            dataIndex: "pinFlag",
            width: 150,
            customRender: (text) => {
              return text
                ? {
                  Y: "转加密",
                  N: "不转加密",
                }[text]
                : "";
            },
          },
          {
            title: "创建时间",
            dataIndex: "createTime",
            width: 200,
          },
          {
            title: "修改时间",
            dataIndex: "updateTime",
            width: 200,
          },
          {
            title: "操作",
            fixed: "right",
            scopedSlots: { customRender: "operation" },
          },
        ],
        dataSource: [],
      };
    },
    methods: {
      onChange(e){
        this.pagination.pageNum = e.current;
        this.pagination.pageSize = e.pageSize;
        this.search();
      },
      async search(e) {
        e && e.preventDefault && e.preventDefault();
        try {
          const res = await this.$get("/admin/igas/pTxnCfg", {
            txnNum: this.query.txnNum,
            bizProdCode: this.query.bizProdCode,
            pageNum : this.pagination.pageNum,
            pageSize: this.pagination.pageSize,
          });
          this.dataSource = res.data.rows;
          this.$set(this.pagination, "total", +res.data.total);
        } catch (e) {
          console.error(e);
        }
      },
      openModal(type = "add", beanInfo) {
        this.modalTitle = {
          add: "新增",
          edit: "修改",
          view: "详情",
          delete: "注销",
        }[type];
        this.modalVisible = true;
        this.$nextTick(() => {
          this.$refs.modalForm.setOperatorType(type);
          if (type === "edit" || type === "view" || type === "delete") {
            this.$refs.modalForm.setBeanInfo(beanInfo);
          }
          this.$refs.modalForm.resetFields();
        });
      },
      async submit() {
        const res = await this.$refs.modalForm.submit();
        if (res) {
          this.modalVisible = false;
          this.pagination.defaultCurrent = 1;
          await this.search();
        }
      },
      edit(item) {
        if(item.supportFlag==='N'){
          return  this.$message.error('已停用数据不能再修改！');
        }
        this.openModal("edit", item);
      },
      view(item) {
        this.openModal("view", item);
      },
      async cancel (item) {
        console.log("item",item);
        try {
          const res = await this.$post('/admin/igas/pTxnCfg/changeStatus',
            {
              txnNum: item.txnNum,
              bizType: item.bizType,
              txnGroup: item.txnGroup,
              bizProdCode: item.bizProdCode,
              supportFlag: item.supportFlag==='N'?'Y':'N'})
          if (res.status === 200) {
            this.$message.success('操作成功')
            this.pagination.defaultCurrent = 1
            await this.search()
          }
        } catch (e) {
          console.error(e)
        }
      }
    },
    mounted() {
      this.search();
    },
  };
</script>
<style lang="less" scoped>
  @import "../../../../../static/less/Common";
</style>
